package com.example.swagger.endpoint;

import com.example.swagger.dto.UserDto;
import com.example.swagger.model.User;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@Api(tags = "用户接口", description = "简易的Swagger接口文档")
@RestController
@RequestMapping(value = "/user", produces = {"application/json", "application/xml"})
public class SimpleEndpoint {

    @ApiOperation(value = "简单的输出信息")
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "成功")
    })
    @GetMapping(value = "/info")
    public ResponseEntity<User> showInfo(String message) {
        return ResponseEntity.ok(new User(1, "Tom", "tom", message));
    }

    @ApiOperation(value = "查询用户")
    @GetMapping(value = "/message")
    public ResponseEntity<User> getUser(UserDto user) {
        return ResponseEntity.ok(new User(user.getId(), user.getName(), "", "查询用户"));
    }

    @ApiOperation(value = "用户集")
    @PostMapping(value = "/list")
    public ResponseEntity<List<User>> listUser() {
        List<User> users = new ArrayList<>();
        users.add(new User(1, "yx", "yx", "yx"));

        return ResponseEntity.ok(users);

    }

    @ApiOperation(value = "删除用户")
    @DeleteMapping(value = "/delete")
    public ResponseEntity<?> deleteUser(String id) {
        return ResponseEntity.ok(null);
    }
}
